<?php
    $dbfoto = $this->database->t_foto;
    $dbuser = $this->database->t_user;

    $query = stripslashes($query);
    $query = mysql_real_escape_string($query);

if ($page=="sphoto") {
    // cari foto
    $querysql = "SELECT * FROM ".$dbfoto."
        INNER JOIN ".$dbuser."
        ON ".$dbfoto.".username_uploader = ".$dbuser.".username
        WHERE (".$dbfoto.".description LIKE '%".$query."%' OR ".$dbfoto.".title LIKE '%".$query."%')
        ORDER BY ".$dbfoto.".title ASC";
    $result = $this->database->execQuery($querysql);
    $count = mysql_num_rows($result);

    if ($count == 0) {
        echo "<div class='image_wrap'><div class='owner'>";
        echo $query." not found!";
        echo "</div></div>";
    }

    for ($i=0;$i<$count;$i++) {
        $img_ext = substr(mysql_result($result, $i, $dbfoto.".img_src"), strrpos(mysql_result($result, $i, $dbfoto.".img_src"), '.'));
        $link_gambar = "profile.php?page=photo-detail&id=".mysql_result($result, $i, $dbuser.".username")."&photo-id=".mysql_result($result, $i, $dbfoto.".id").$img_ext;
        $link_profile = "profile.php?id=".mysql_result($result, $i, $dbuser.".username");
        $source_gambar = mysql_result($result, $i, $dbfoto.".img_src");
        $source_profile = mysql_result($result, $i, $dbuser.".fullname");
        $source_title = mysql_result($result, $i, $dbfoto.".title");
?>
    <div class="image_wrap">
        <a href="<?php echo $link_gambar; ?>">
            <div class="top"></div>
            <div class="left"></div>
            <div class="image_thumbnail">
                <img alt="contoh" src="<?php echo $source_gambar; ?>"/>
            </div>
            <div class="right"></div>
            <div class="clear_both"></div>
            <div class="bottom"></div>
        </a>
        <div class="title"><?php echo $source_title?></div>
        <div class="owner">By <a href="<?php echo $link_profile; ?>"><?php echo $source_profile; ?></a></div>
    </div>
<?php
    }
}
else {
// cari user
    $querysql = "SELECT * FROM ".$dbuser."
        WHERE (".$dbuser.".username LIKE '%".$query."%' OR ".$dbuser.".fullname LIKE '%".$query."%')
        ORDER BY ".$dbuser.".fullname ASC";
    $result = $this->database->execQuery($querysql);
    $count = mysql_num_rows($result);

    if ($count == 0) {
        echo "<div class='image_wrap'><div class='owner'>";
        echo $query." not found!";
        echo "</div></div>";
    }

    for ($i=0;$i<$count;$i++) {
        $link_profile = "profile.php?id=".mysql_result($result, $i, $dbuser.".username");
        $source_foto = mysql_result($result, $i, $dbuser.".img_location");
        $source_username = mysql_result($result, $i, $dbuser.".username");
        $source_fullname = mysql_result($result, $i, $dbuser.".fullname");
        $source_location = mysql_result($result, $i, $dbuser.".location");
?>
        <div class="user_wrap">
            <a href="<?php echo $link_profile; ?>">
                <div class="bar"></div>
                <img alt="contoh" src="<?php echo $source_foto; ?>"/>
                <div class="iname">
                    <div class="ifullname"><?php echo $source_fullname." (".$source_username.")"; ?></div>
                    <div class="ilocation">From <?php echo $source_location; ?></div>
                </div>
                <div class="clear_both"></div>
            </a>
        </div>
<?php        
    }
}
?>
